package com.wmada.toolkit.common.secure;

/**
 * @author will.ma
 * @date 2017/3/11
 */
public class AESUtils {

    private static final String algorithm    = "AES/ECB/PKCS5Padding";
    private static final String keyAlgorithm = "AES";

    public static String encode(String message, String password) {
        if (message != null && password != null && password.length() == 16) {
            return (new Encrypt(algorithm, keyAlgorithm, password)).encrypt(message);
        } else {
            return null;
        }
    }

    public static String encode(String message, byte[] password) {
        if (message != null && password != null && password.length == 16) {
            return (new Encrypt(algorithm, keyAlgorithm, password)).encrypt(message);
        } else {
            return null;
        }
    }

    public static byte[] encode(byte[] data, String password) {
        if (data != null && password != null && password.length() == 16) {
            return (new Encrypt(algorithm, keyAlgorithm, password)).encrypt(data);
        } else {
            return null;
        }
    }

    public static byte[] encode(byte[] data, byte[] password) {
        if (data != null && password != null && password.length == 16) {
            return (new Encrypt(algorithm, keyAlgorithm, password)).encrypt(data);
        } else {
            return null;
        }
    }

    public static String decode(String secret, String password) {
        if (secret != null && password != null && password.length() == 16) {
            return (new Decrypt(algorithm, keyAlgorithm, password)).decrypt(secret);
        } else {
            return null;
        }
    }

    public static String decode(String secret, byte[] password) {
        if (secret != null && password != null && password.length == 16) {
            return (new Decrypt(algorithm, keyAlgorithm, password)).decrypt(secret);
        } else {
            return null;
        }
    }

    public static byte[] decode(byte[] data, String password) {
        if (data != null && password != null && password.length() == 16) {
            return (new Decrypt(algorithm, keyAlgorithm, password)).decrypt(data);
        } else {
            return null;
        }
    }

    public static byte[] decode(byte[] data, byte[] password) {
        if (data != null && password != null && password.length == 16) {
            return (new Decrypt(algorithm, keyAlgorithm, password)).decrypt(data);
        } else {
            return null;
        }
    }

}
